<script setup>
import { specialRoomListCommon } from '@/components/roomConstant/common.js';
import ExcelExport from '@/components/common/excelExport.vue';

const props = defineProps({
  dataSource: {
    type: Array,
    default: () => []
  },
  fullModalClass: {
    type: String,
    default: ''
  },
  isImport: {
    type: Boolean,
    default: false
  },
});

const columns = [
  {
    title: '房间号/名称',
    dataIndex: 'name',
    align: 'center'
  },
  // {
  //   title: '使用单位',
  //   dataIndex: 'roomUseUnit',
  //   align: 'center',
  //   customRender: ({ text }) => {
  //     return specialRoomListCommon.roomUseUnit[text]?.name;
  //   }
  // },
  // {
  //   title: '使用人',
  //   dataIndex: 'roomUsePeople',
  //   align: 'center',
  //   customRender: ({ text }) => {
  //     return text;
  //   }
  // },
  {
    title: '面积(㎡)',
    dataIndex: 'area',
    align: 'center'
  },
];

const isFull = ref();

const tableDataSource = ref();

// 搜索
const onSearch = (value) => {
  if (!value) {
    tableDataSource.value = props.dataSource;
  } else {
    tableDataSource.value = props.dataSource.filter(item =>
        item.name.includes(value)
    );
  }
};


watch(() => props.fullModalClass, (val) => {
  isFull.value = val;
});

watch(() => props.dataSource, (val) => {
  tableDataSource.value = val;
}, { immediate: true });
</script>

<template>
  <div class="table-container">
    <div class="top">
      <div class="search">
        <a-input-search
            enter-button
            allowClear
            @search="onSearch"
            placeholder="请输入房间号/名称"
            style="width: 220px" />
      </div>
      <excel-export v-if="!isImport" :dataSource="dataSource" />
    </div>
    <div class="table">
      <a-table
          :columns
          :dataSource="tableDataSource"
          size="small"
          :scroll="{ y: isFull === 'full-modal' ? 620 : 590 }"
          bordered
          :pagination="{
                position: ['bottomCenter'],
                showSizeChanger: true,
                showTotal: total => `总数：${total}`,
                pageSizeOptions: ['15', '20', '50', '100'],
                defaultPageSize: 15,
                locale: {
                  items_per_page: '条/页',
                  }
              }"
      >
      </a-table>
    </div>
  </div>
</template>

<style scoped lang="scss">
.table-container {
  width: 380px;
  min-height: 700px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;

  .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
  }

  .table {
    flex: 1;
    position: relative;

    .ant-table-wrapper,
    :deep(.ant-spin-nested-loading),
    :deep(.ant-spin-container) {
      width: 100%;
      height: 100%;
    }

    :deep(.ant-table-container) {
      overflow: hidden;
      display: flex;
      flex-direction: column;

      .ant-table-body {
        flex: 1;

        &::-webkit-scrollbar {
          width: 8px; /* 垂直滚动条宽度 */
          height: 8px; /* 水平滚动条高度 */
        }

        /* 滚动条滑块 */
        &::-webkit-scrollbar-thumb {
          background: rgba(175, 175, 175, 0.5);
          border-radius: 4px;

          &:hover {
            background: rgba(175, 175, 175, 0.5); /* 悬停效果 */
          }
        }
      }
    }

    :deep(.ant-spin-container) {
      display: flex;
      flex-direction: column;
      //justify-content: space-between;
      position: absolute;

      & > div {
        flex: 1;
      }
    }
  }

  .ant-btn {
    &:hover {
      filter: opacity(0.8);
    }
  }
}
</style>
